package com.yogee.topseller.fragment.zhoubian;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.ProductDetailsActivity;
import com.yogee.topseller.activity.ZhoubianActivity;
import com.yogee.topseller.adapter.JigouAdapter;
import com.yogee.topseller.bean.JigouBean;
import com.yogee.topseller.bean.ProductInfoBean;
import com.yogee.topseller.fragment.productdetail.BaseFragment;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.utils.LogUtils;
import com.yogee.topseller.view.MyScrollView;
import com.yogee.topseller.view.PublicStaticClass;
import com.yogee.topseller.view.PullUpToLoadMore;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 相关产品
 * Created by zwj on 2017/12/7.
 */

public class JigouFragment extends BaseFragment implements ZhoubianActivity.UpdateListener{

    @BindView(R.id.rv_rongzi)
    RecyclerView rv_rongzi;

    JigouAdapter jigouAdapter1;
    List<JigouBean.Company> list1 = new ArrayList<>();
    Unbinder unbinder1;
    private int isMj = 0;
    private String proId = "";  // 产品id
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_product_jigou;
    }


    @Override
    protected void initView() {
//        ((ProductDetailsActivity)getActivity()).setListener(this);
//        beans = (ProductInfoBean) getArguments().getSerializable("baseInfo");
//        list = beans.getInterest();

        isMj = getArguments().getInt("isMj");
        proId = getArguments().getString("proId");
        rv_rongzi.setLayoutManager(new LinearLayoutManager(getActivity()));
//        jigouAdapter1 = new JigouAdapter(getActivity(),rv_rongzi,((ZhoubianActivity)getActivity()).getListener());
        rv_rongzi.setAdapter(jigouAdapter1);
//        jigouAdapter1.addData(list1);
        getCpjg();
    }

    /**
     * 获取产品机构
     */
    private void getCpjg(){
        HttpManager.getInstance().relatedCompanyTypeDetails(proId,isMj+"").compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<JigouBean>() {
            @Override
            public void onNext(JigouBean o) {
//                list1.addAll(o.getMechanismList());
                jigouAdapter1.addData(o.getMechanismList());

            }
        }, this));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder1 = ButterKnife.bind(this, rootView);

        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder1.unbind();
    }

    @Override
    public String getTitle() {
        return "机构相关";
    }


    @Override
    public void getCurrentPos(JigouBean.Company company) {

    }


}
